import 'package:flutter/material.dart';
import 'package:flutter_menu/app_config.dart';
import 'package:flutter_menu/biz/order/order_pg.dart';
import 'package:flutter_menu/data/base_provider.dart';
import 'package:flutter_menu/model/formula_model.dart';
import 'package:flutter_menu/model/menu_model.dart';
import 'package:flutter_menu/model/product_model.dart';
import 'package:flutter_menu/model/sellout_model.dart';
import 'package:flutter_menu/objectbox.g.dart';

class SelloutProvider extends BaseProvider<SelloutModel> {
  SelloutProvider(super.store);

  Future<List<SelloutModel>> getFormulaListAsync() {
    return box.getAllAsync();
  }

  SelloutModel? getSelloutModelWithSpecId(String specId) {
    return box
        .query(
            SelloutModel_.typeId.equals(specId) & SelloutModel_.type.equals(1))
        .build()
        .findFirst();
  }

  /// 根据id获取沽清详情
  /// @param typeId 规格id 或者 选项id 或者 原料id
  /// @param type 1规格 2选项 3原料
  /// @return
  Future<SelloutModel?> getSelloutDetails(String typeId, int type) async {
    return getDefaultSelloutDetails(typeId, type);
  }

  /// 获取默认的沽清详情
  /// @param typeId
  /// @param type
  /// @return
  Future<SelloutModel?> getDefaultSelloutDetails(
      String typeId, int type) async {
    return box
        .query(SelloutModel_.typeId.equals(typeId) &
            SelloutModel_.type.equals(type))
        .build()
        .findFirstAsync();
  }
}

///  0x000 无沽清状态
///  0x001 原料沽清
///  0x010 选项沽清
///  0x011 原料和选项沽清
///  0x100 规格沽清
///  0x101 原料和规格沽清
///  0x110 规格和选项沽清
///  0x111 规格、选项和原料全部沽清
class ProductSelloutStatus {
  static const int NONE = 0x000;
  static const int MATERIAL = 0x001;
  static const int OPTION = 0x010;
  static const int OPTION_MATERIAL = 0x011;
  static const int SPEC = 0x100;
  static const int SPEC_MATERIAL = 0x101;
  static const int SPEC_OPTION = 0x110;
  static const int SPEC_OPTION_MATERIAL = 0x111;
}
